﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using MixScript.BLL;

namespace MixScript.BLL.FI
{
    public class Posting : cBaseBLL
    {
        public Posting() { }


        /// <summary>
        /// cAccHeader
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="posting"></param>
        /// <param name="slipType"></param>
        /// <param name="dateFrom"></param>
        /// <param name="dateTo"></param>
        /// <returns></returns>
        public bool getPosting(out DataTable dt, Int32 posting, Int32 slipType, DateTime dateFrom, DateTime dateTo)
        {
            string sType = "";
            if (slipType != 0)
                sType = "sliptype = " + slipType + " AND ";
            string sSql = @"SELECT slipid,cast(slipdate as NVARcHAR(11)) AS slipdatedmy,slipcode,slipnum,slipcurr,
            slipdesc FROM accsliphdr
            WHERE posting = {0}  AND {1}
            slipdate BETWeen '{2}' AND '{3}'
            ORDER BY slipdate,sliptype DESC";
            try
            {
                dt = Dbserver.ExecuteQuery(string.Format(sSql, posting, sType, string.Format("{0:yyyy-MM-dd}", dateFrom.ToString()), string.Format("{0:yyyy-MM-dd}", dateTo.ToString())), "Posting");
                return dt.Rows.Count > 0;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// cAccHeader
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="posting"></param>
        /// <param name="slipType"></param>
        /// <param name="dateFrom"></param>
        /// <param name="dateTo"></param>
        /// <returns></returns>

        public bool ExecutePosting(Int32 slipID, bool isPosting)
        {
            string sSql = @"Update accsliphdr
            SET posting = {0}  where slipid = '{1}'";
            try
            {
                Dbserver.openConn();
                Dbserver.ExecuteNonQuery(string.Format(sSql, Convert.ToInt32(isPosting), slipID));
                Dbserver.CommitAndCloseConn();
                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }




    }
}

